<template>
    <div class="doctor-register">
        <h1>医生注册</h1>
        <form @submit.prevent="submitForm">
            <div>
                <label for="name">姓名:</label>
                <input type="text" id="name" v-model="form.name" required />
            </div>
            <div>
                <label for="specialty">专科领域:</label>
                <input type="text" id="specialty" v-model="form.specialty" required />
            </div>
            <div>
                <label for="introduction">简介:</label>
                <textarea id="introduction" v-model="form.introduction" required></textarea>
            </div>
            <div>
                <label for="hospital">所属医院:</label>
                <input type="text" id="hospital" v-model="form.hospital" required />
            </div>
            <div>
                <label for="medicalLicenseNumber">执业证书编号:</label>
                <input type="text" id="medicalLicenseNumber" v-model="form.medicalLicenseNumber" required />
            </div>
            <button type="submit">提交</button>
        </form>
    </div>
</template>

<script>
import { registerdoctor } from '@/api/user'; // Adjust the import path as necessary

export default {
    data() {
        return {
            form: {
                userId: parseInt(localStorage.getItem('id')) || null,
                name: '',
                specialty: '',
                introduction: '',
                hospital: '',
                medicalLicenseNumber: ''
            }
        };
    },
    methods: {
        async submitForm() {
            if (!this.form.userId) throw new Error('用户 ID 未设置');

                const numericValue = parseInt(this.form.userId, 10);
            if (isNaN(numericValue)) {
                throw new Error(`用户 ID 格式错误: ${this.form.userId}`);
            }
            this.form.userId = numericValue;

            const response = await registerdoctor(this.form);
            
            
                this.$router.push({ name: 'Login' });
            

        }
    }
};
</script>

<style scoped>
.doctor-register {
    max-width: 600px;
    margin: 0 auto;
}
form div {
    margin-bottom: 15px;
}
label {
    display: block;
    margin-bottom: 5px;
}
input,
textarea {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}
button {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    cursor: pointer;
}
button:hover {
    background-color: #0056b3;
}
</style>